package tdd.taxi;

import tdd.printer.Printer;

import java.math.BigDecimal;

public class Taxi {
    private static final int INIT_PRICE_FEN = 600;
    private static final int WAITING_PRICE_FEN = 25;
    private static final int UNIT_PRICE_FEN = 80;
    private static final int INIT_DISTANCE = 2;

    private Printer printer;

    public Taxi() {
    }

    public Taxi(Printer printer) {
        this.printer = printer;
    }

    public BigDecimal calculate(int distance, int minutes) {
        int result = minutes <= 0 ? 0 : minutes * WAITING_PRICE_FEN;
        if (distance > INIT_DISTANCE && distance <= 8) {
            result += INIT_PRICE_FEN + UNIT_PRICE_FEN * (distance - INIT_DISTANCE);
        } else if (distance > 8) {
            result += INIT_PRICE_FEN + UNIT_PRICE_FEN * 6 + (int)(UNIT_PRICE_FEN * 1.5 * (distance - 8));
        } else {
            result += INIT_PRICE_FEN;
        }
        return convertToYuan(result);
    }

    public BigDecimal submit(int distance, int minutes) {
        BigDecimal money = calculate(distance, minutes);
        printer.print("里程：" + distance + "，等待时间：" + minutes + "，金额：" + money);
        pay(money);
        return money;
    }

    public void pay(BigDecimal money) {
        throw new UnsupportedOperationException();
    }

    private BigDecimal convertToYuan(int fen) {
        return BigDecimal.valueOf(fen, 2);
    }
}
